<?php
session_start();

header("content-type:text/html;charset=utf-8");
include_once("../function.php");
if ($_GET['id']!=NULL){
    $goods=que_select_cl('goods',$_GET['id']);
}

if (!empty($_POST['gid']) && !empty($_POST['uid'])){
   $where = "where uid='".$_POST['uid']."' and gid='".$_POST['gid']."'";
   $res = que_select_cl_where('car',$where);
   if(!empty($res['id'])){
	   echo 2;
   }else{
		$data = array(
		   'gid' => intval($_POST['gid']),
		   'uid' => $_POST['uid']
		);
		$res = add_insert_cl('car',$data);
		if($res){
		   echo 1;
		}else{
		   echo 0;
		}
   }
   
   exit;
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>商品详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!--标准mui.css-->
    <link rel="stylesheet" href="css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="css/app.css" />
    <link rel="stylesheet" type="text/css" href="css/icons-extra.css">
    <!--自定义iconfont-->
    <link rel="stylesheet" type="text/css" href="css/iconfont.css">
</head>

<?php

if ($_POST['checkout']){
    echo "<script language=javascript>window.location.href='shoppingcheckout.php'</script>";
}
?>

<body style="background: #fff;">

<div class="new-personal-details">
    <!--图片轮播-->
    <div class="mui-slider-item">
        <a href="#"><img src="../upload/<?=$goods['goodsimg']?>" style="width: 100%;"></a>
    </div>

    <ul class="deails-con">
        <li class="deails-con-title"><?=$goods['goodsname']?></li>
        <li class="deails-con-price">
            <span>￥<?=$goods['price']?>起</span>
            <span>库存:<label><?=$goods['kucun']?></label></span>
        </li>
        <li class="deails-con-text">商品详情</li>
        <li class="deails-con-text__li">
            <?=$goods['goodscontent']?>
        </li>
    </ul>
</div>
<ul class="details-price__button">
    <li class="add-cart clickwn">

    </li>
    <li class="buy">加入购物车</li>
</ul>


<input type='hidden' name='paramid' value="<?php echo $goods['id']; ?>" />
<input type='hidden' name='paramname' value="<?php echo $_SESSION['userid']; ?>" />

<script src="js/mui.min.js"></script>
</body>

</html>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script type="text/javascript">
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });
    $(function() {
        $(".buy").click(function() {
            var gid = $("input[name=paramid]").val();
            var uid = $("input[name=paramname]").val();
            $.ajax({
                url:"goodscontent.php",
                type:"post",
                dataType:"html",
                data:"gid="+gid+"&uid="+uid,
                success:function(data){
                    if(data == 2){
                        var btnArray = ['否', '是'];
                        mui.confirm('该商品已经在购物车，是否前往结算？', '', btnArray, function(e) {
                            if (e.index == 1) {
                                window.location.href = 'goodslist3.php';
                            } else {
                                mui.alert("关闭对话框！","","确定");
                            }
                        })
					  }else{
						if(data == 1){
                            mui.confirm('加入购物车成功，是否前往结算？', '', btnArray, function(e) {
                                if (e.index == 1) {
                                    window.location.href = 'goodslist3.php';
                                } else {
                                    mui.alert("关闭对话框！","","确定");
                                }
                            })
						}else{
							mui.toast('加入购物车失败');
						}
					}
                }
            });
        })

    })
</script>